package me.pearjelly.pmc.dao.impl;

import java.util.List;

import me.pearjelly.pmc.dao.PicGroupDAO;
import me.pearjelly.pmc.util.Logger;

import org.springframework.jdbc.core.JdbcTemplate;

public class PicGroupJDBCDAO implements PicGroupDAO {
	
	@Override
	public void updateIndexFlag(List<Long> list) {
		StringBuilder sql = new StringBuilder("update PICGROUPS set INDEXFRAG=1 where ID in ( ");
		for (Long id : list) {
			if(id>0){
				sql.append(id).append(",");
			}
		}
		if(list.size() > 0){
			sql.deleteCharAt(sql.length()-1);
			sql.append(")");
			String finalSql = sql.toString();
			
			int rows = jdbcTemplate.update(finalSql);
			
			log.debug("Update %d rows, sql : <%s>.", rows, finalSql);
		}else{
			log.debug("No Update, list size 0.");
		}
		
	}
	private static Logger log = new Logger();
	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
}
